package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.mapper.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分类与属性管理service实现类
 */
@Service
public class ManageServiceImpl implements ManageService {

    @Autowired
    BaseCategory1Mapper baseCategory1Mapper;
    /**
     * 查询所有一级分类列表
     * @return
     */
    @Override
    public List<BaseCategory1> getCategory1List() {
        return baseCategory1Mapper.selectList(null);
    }

    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;
    /**
     * 根据一级分类id查询二级分类
     * @param category1Id 一级分类id
     * @return
     */
    @Override
    public List<BaseCategory2> getCategory2List(Long category1Id) {
        //传入参数判断
        if(category1Id == null)
            throw new RuntimeException("请先选择一级分类");
        //创建查询条件
        LambdaQueryWrapper<BaseCategory2> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategory2::getCategory1Id,category1Id);
        //执行查询并返回
        return baseCategory2Mapper.selectList(queryWrapper);
    }

    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;
    /**
     * 根据二级分类id查询三级分类
     * @param category2Id 二级分类id
     * @return
     */
    @Override
    public List<BaseCategory3> getCategory3List(Long category2Id) {
        //传入参数判断
        if(category2Id == null)
            throw new RuntimeException("请先选择二级分类");
        //创建查询条件
        LambdaQueryWrapper<BaseCategory3> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategory3::getCategory2Id,category2Id);
        //执行查询并返回
        return baseCategory3Mapper.selectList(queryWrapper);
    }

    @Autowired
    private BaseAttrInfoMapper baseAttrInfoMapper;
    /**
     * 查询1 2 3级分类对应的规格信息列表，若只查询某一个分类下的规格列表则其他分值传0
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @Override
    public List<BaseAttrInfo> getBaseAttrInfoList(Long category1Id,
                                                  Long category2Id,
                                                  Long category3Id) {
       List<BaseAttrInfo> baseAttrInfoList = baseAttrInfoMapper.selectBaseAttrInfoList(category1Id,category2Id,category3Id);
        return null;
    }
}
